// Copyright 2019, Chen Shuaihao.
//
//Author: Chen Shuaihao
//
//Poller类，对epoll的封装

#ifndef _Connection_H_
#define _Connection_H_

#include <vector>
#include <mutex>
#include <list>
#include <atomic> 
#include <sys/epoll.h>
#include "Net.h"

using namespace std;

class CConnection
{
public:
	 CConnection();
	~CConnection();
private:
    //保护连接对象的互斥量
    std::mutex 						m_MutexConn; 
	//和连接池有关的
	std::list<sClient*>			m_ConnectionList;							//连接列表
	
	std::list<sClient*>			m_FreeConnectionList;						//空闲连接列表

	std::atomic<int>				m_nTotalConnections;						//连接池总连接数
	
	std::atomic<int>				m_nFreeConnections;							//连接池空闲连接数
	
	int										m_worker_connections;                 		
public:
	//初始化连接池
	void InitConnections();										

	//回收连接池
	void ClearConnections();																				

	//从连接池中获取一个空闲连接
	sClient*GetConnection(int isock);

	//归还参数pConn所代表的连接到到连接池中	
	void FreeConnection(sClient*pConn);
	
};
#endif